﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using com.codebump;

public partial class Clerisy_Clerisy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString.HasKeys())
            {
                if (Request.QueryString["listid"] != String.Empty)
                    Session["listid"] = Request.QueryString["listid"];
                else
                    Session["listid"] = 1;

                
                if (Request.QueryString["dnis"] != null)
                {
                    Session["dnis"] = Request.QueryString["dnis"];
                }
                else
                {
                    Session["dnis"] = "9999999999";
                }

                Session["servername"] = Request.QueryString["servername"];
                Session["projectname"] = Request.QueryString["projectname"];
                Session["campaignname"] = Request.QueryString["campaignname"];
                Session["agentid"] = Request.QueryString["agentid"];
                Session["agentfirst"] = Request.QueryString["agentfirst"];
                Session["agentlast"] = Request.QueryString["agentlast"];

                Session["App"] = new DataAccess();

                //ValidateIBListID();
            }
            tbListid.Text = Session["listid"].ToString();
            WebWizard.ActiveStepIndex = 0;

            //The session variables are requested in the master page currently using the following syntax: Session["servername"] = Request.QueryString["servername"];
            //The page is loaded before the master page so if the code isn't in a control, it will currently error out.
            //((DataAccess)Session["App"]).ConnectInbound(Session["servername"].ToString(), Session["projectname"].ToString(), Session["campaignname"].ToString(), Session["dnis"].ToString(), Session["listid"].ToString());

            Session["total"] = 0.00;

            //the following block of code specifies the years for cc expiration date validation and adds that to the error message (dynamically)
            int yearval;
            yearval = Convert.ToInt32(DateTime.Today.ToString("yy"));
            rvExpYear.MinimumValue = yearval.ToString();
            rvExpYear.ErrorMessage += "(" + yearval.ToString() + " - ";
            rvExpYear.MaximumValue = (yearval + 10).ToString();
            rvExpYear.ErrorMessage += (yearval + 10).ToString() + ")";
        }
        
    }
    //POST LOGIC - For Step or Start pages
    //Add if statements as you add pages
    //For Next and Finish pages it is best to use the index in the if statements as below
    protected void WebWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {

            if (pnlDispo.Visible == true)
            {
                //"add no products";
                WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);

            }
            else if (pnlNoAuto.Visible == true || pnlFinalRebuttal.Visible == true)
            {
                lblrProd.Text = "a 30-day supply of Nasal Soft Strips";
                Session["total"] = 65.90;
                lblProdinsert.Text = "noauto";
                //add product noautoship
                //putorder("productid", IDofNoAutohip)
            }
            else
            {
                lblrProd.Text = "our free 14-day supply of nasal soft strips with the 30 day auto-shipment option";
                pnlAutoshipConf.Visible = true;
                ddlPayMethod.Items.RemoveAt(2);
                Session["total"] = 7.95;
                lblProdinsert.Text = "auto";
                //add product autoship
                //putorder("productid", IDofAutoship)
                //Label1.Text = "Added product with autoship";
            }

            return;
        }

        if (page == WebWizard.WizardSteps.IndexOf(this.CustomerInfo))
        {
            string sCity;
            string sShipCity;
            if (tbCity.Visible == true)
            {
                sCity = tbCity.Text;
            }
            else
            {
                sCity = ddlCity.SelectedItem.Text;
            }
            if (tbShipCity.Visible == true)
            {
                sShipCity = tbShipCity.Text;
            }
            else
            {
                sShipCity = ddlShipCity.SelectedItem.Text;
            }

            //if shipping info is not visible, write billing info for all fields
            if (!pnlShip.Visible)
            {
                ((DataAccess)Session["App"]).PutCallData("ShipFirstName", tbFirstName.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipLastName", tbLastName.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbAddr.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbAddr2.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipCity", sCity);
                ((DataAccess)Session["App"]).PutCallData("ShipState", ddlState.SelectedValue.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlCountry.SelectedValue.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipZip", tbZip.Text.ToString());

                if (tbAddr2.Text != "")
                {
                    lblrAddress.Text = "<br/>" + tbAddr.Text + "<br/>" + tbAddr2.Text + "<br/> " + sCity + ", " + ddlState.SelectedValue.ToString() + "<br/>" + ddlCountry.SelectedItem.Text + "<br/>" + tbZip.Text + "<br/>";
                }
                else
                {
                    lblrAddress.Text = "<br/>" + tbAddr.Text + "<br/>" + sCity + "<br/>" + ddlState.SelectedValue.ToString() + ", " + ddlCountry.SelectedItem.Text + "<br/>" + tbZip.Text + "<br/>";
                }

                //fill hidden data with data from visible portion
                //tbshipFirstName.Text = tbFirstName.Text;
                //tbshipLastName.Text = tbLastName.Text;
                //tbshipAddr.Text = tbAddr.Text;
                //tbshipAddr2.Text = tbAddr2.Text;
                //tbshipCity.Text = tbCity.Text;
                //ddlShipState.SelectedIndex = ddlState.SelectedIndex;
                //ddlShipCanadaState.SelectedIndex = ddlCanadaState.SelectedIndex;
                //tbshipZip.Text = tbZip.Text;
                //ddlShipCountry.SelectedIndex = ddlCountry.SelectedIndex;

                //if the shipping info is invisible then write appropriate state and ship state to the db
                //based on if state list or canada state list is visible (ship state will be the same as visible state)
                //if (ddlState.Visible)
                //{
                //    ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedValue.ToString());

                //    //((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedValue.ToString());
                //}
                //else
                //{
                //    ((DataAccess)Session["App"]).PutCallData("State", ddlCanadaState.SelectedValue.ToString());
                //    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlCanadaState.SelectedValue.ToString());
                //    //((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipCanadaState.SelectedValue.ToString());
                //}
            }
            else
            {

                ((DataAccess)Session["App"]).PutCallData("ShipFirstName", tbshipFirstName.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipLastName", tbshipLastName.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipAddress1", tbshipAddr.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipAddress2", tbshipAddr2.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipCity", sShipCity);
                ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipState.SelectedValue.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipZip", tbShipZip.Text.ToString());
                ((DataAccess)Session["App"]).PutCallData("ShipCountry", ddlShipCountry.SelectedValue.ToString());

                if (tbshipAddr2.Text != "")
                {
                    lblrAddress.Text = "<br/>" + tbshipAddr.Text + "<br/>" + tbshipAddr2.Text + "<br/> " + sShipCity + ", " + ddlShipState.SelectedValue.ToString() + "<br/>" + ddlShipCountry.SelectedItem.Text + "<br/>" + tbShipZip.Text + "<br/>";
                }
                else
                {
                    lblrAddress.Text = "<br/>" + tbshipAddr.Text + "<br/>" + sShipCity + ", " + ddlShipState.SelectedValue.ToString() + "<br/>" + ddlShipCountry.SelectedItem.Text + "<br/>" + tbShipZip.Text + "<br/>";
                }
                //if shipping info is visible, write state and ship state info to db based on what ddl is visible
                //if (ddlState.Visible)
                //{
                //    ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedValue.ToString());
                //}
                //else
                //{
                //    ((DataAccess)Session["App"]).PutCallData("State", ddlCanadaState.SelectedValue.ToString());
                //}
                //if (ddlShipState.Visible)
                //{

                //}
                //else
                //{
                //    ((DataAccess)Session["App"]).PutCallData("ShipState", ddlShipCanadaState.SelectedValue.ToString());
                //}
            }
            ((DataAccess)Session["App"]).PutCallData("FirstName", tbFirstName.Text.ToString());
            ((DataAccess)Session["App"]).PutCallData("LastName", tbLastName.Text.ToString());
            ((DataAccess)Session["App"]).PutCallData("Address1", tbAddr.Text.ToString());
            ((DataAccess)Session["App"]).PutCallData("Address2", tbAddr2.Text.ToString());
            ((DataAccess)Session["App"]).PutCallData("City", sCity);//ddlCity.SelectedValue.ToString().Substring(3));
            ((DataAccess)Session["App"]).PutCallData("State", ddlState.SelectedValue.ToString());
            ((DataAccess)Session["App"]).PutCallData("Country", ddlCountry.SelectedValue.ToString());
            ((DataAccess)Session["App"]).PutCallData("Zip", tbZip.Text.ToString());

            //***********************
            string phone = tbPriPhone.Text.ToString().Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
            string phone2 = tbSecPhone.Text.ToString().Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "");
            ((DataAccess)Session["App"]).PutCallData("PrimaryPhone", phone);
            ((DataAccess)Session["App"]).PutCallData("AlternatePhone", phone2);
            ((DataAccess)Session["App"]).PutCallData("Email", tbEmail.Text.ToString());


            //determines if the recap page shows canadian or us state
            //string StateProv;
            //if (ddlShipCountry.SelectedIndex == 1)
            //{
            //    StateProv = ddlShipCanadaState.SelectedItem.Text;
            //}
            //else
            //{
            //    StateProv = ddlShipState.SelectedItem.Text;
            //}


            //if (tbshipAddr2.Text != "")
            //{
            //    lblrAddress.Text = "<br/>" + tbshipAddr.Text + "<br/>" + tbshipAddr2.Text + "<br/> " + ddlShipCity.SelectedItem.Text + "<br/>" + StateProv + "<br/>" + ddlShipCountry.SelectedItem.Text + "<br/>" + tbShipZip.Text + "<br/>";
            //}
            //else
            //{
            //    lblrAddress.Text = "<br/>" + tbshipAddr.Text + "<br/>" + ddlShipCity.SelectedItem.Text + "<br/>" + StateProv + "<br/>" + ddlShipCountry.SelectedItem.Text + "<br/>" + tbShipZip.Text + "<br/>";
            //}
            lblrName.Text = tbFirstName.Text + " " + tbLastName.Text + ", ";

            lblrOrderNum.Text = Session["listid"].ToString() + ".";
            lblrLastName.Text = tbLastName.Text;
            lblrDate.Text = DateTime.Today.ToString("d") + ", ";
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.PayMethod))
        {

            ((DataAccess)Session["App"]).PutCallData("PaymentMethod", ddlPayMethod.SelectedItem.Value.ToString());
            // ("FirstName", "test");

            if (pnlCCInfo.Visible)
            {

                ((DataAccess)Session["App"]).PutCallData("CCType", ddlCardType.SelectedItem.Value.ToString());
                ((DataAccess)Session["App"]).PutCallData("CCNumber", ((DataAccess)Session["App"]).EnryptData(tbCCNum.Text));
                ((DataAccess)Session["App"]).PutCallData("CCV", ((DataAccess)Session["App"]).EnryptData(tbCCV.Text));
                if (tbExpMonth.Text.Trim().Length < 2)
                {
                    ((DataAccess)Session["App"]).PutCallData("CCExpiry", "0" + tbExpMonth.Text + tbExpYear.Text);
                }
                else
                {
                    ((DataAccess)Session["App"]).PutCallData("CCExpiry", tbExpMonth.Text + tbExpYear.Text);
                }

                if (tbCCNum.Text.Length >= 4)
                {
                    lblCClast4.Text = tbCCNum.Text.Substring(tbCCNum.Text.Length - 4);
                }
                tbCCNum.Text = "";
                tbCCV.Text = "";
                tbExpMonth.Text = "";
                tbExpYear.Text = "";
            }
            if (pnlBankInfo.Visible)
            {
                ((DataAccess)Session["App"]).PutCallData("BankName", tbBankName.Text);
                ((DataAccess)Session["App"]).PutCallData("AccountNum", ((DataAccess)Session["App"]).EnryptData(tbAcctNum.Text));
                ((DataAccess)Session["App"]).PutCallData("RoutingNum", tbRoutingNum.Text);
                ((DataAccess)Session["App"]).PutCallData("CheckNum", tbCheckNum.Text);
                tbBankName.Text = "";
                tbAcctNum.Text = "";
                tbRoutingNum.Text = "";
                tbCheckNum.Text = "";
            }
            return;

        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Upsell))
        {

            if (cbStressReliefStrips.Checked)
            {
                lblrUpsell.Text = "with our 30-day supply of Stress Relief Strips";
                //Session["total"] = Convert.ToDouble(Session["total"]) + 29.95; //put in on checkedchanged in case sb hits back
                //Label1.Text = "added strrelstrps";
                //putorder("productid", IDofStressReliefStrips);
            }
            if (cbRushShipping.Checked)
            {
                //Session["total"] = Convert.ToDouble(Session["total"]) + 7.00; //put in on checkedchanged in case sb hits back
                if (cbStressReliefStrips.Checked)
                {
                    lblrUpsell.Text = "with our 30-day supply of Stress Relief Strips and rush shipping";
                }
                else
                {
                    lblrUpsell.Text = "with rush shipping";
                }

                //Label2.Text = "added rushship";
                //putorder("productid", IDofRushShip;
            }
            decimal total = Convert.ToDecimal(Session["total"]);
            lblrTotal.Text = "$" + total.ToString("0.00") + ".";
            //lblrTotal.Text = Session["total"].ToString();

        }

        if (page == WebWizard.WizardSteps.IndexOf(this.FinishPageID))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }



    }

    //POST LOGIC for disposition pages
    //this is for pages that contain a disposition button
    protected void WebWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {

        int page = WebWizard.ActiveStepIndex;
        if (page == WebWizard.WizardSteps.IndexOf(this.Intro))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Upsell))
        {
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.FinishPageID))
        {
            //Change These two lines of code - For Information Only
            ((DataAccess)Session["App"]).PutCallData("webusercode", "Q0");

            WebWizard.ActiveStepIndex = WebWizard.WizardSteps.IndexOf(this.Disposition);
            return;
        }
        if (page == WebWizard.WizardSteps.IndexOf(this.Disposition))
        {
            return;
        }


    }

    //PRE-LOGIC
    //Add if statements as needed for post-logic
    //You can use the Step ID name instead of the index as used in Next and Finish logic.
    protected void WebWizard_ActiveStepChanged(object sender, EventArgs e)
    {
        if (WebWizard.ActiveStep.Title.ToString() == "Disposition")
        {
            NonSaleDispo.Visible = false;
            //insert order information
            //string sQuery = "insert into orders (enterpriseListid, CampaignID, ProductID, ProductTypeID, ProductDesc, BaseRevenue, Quantity) ";
            //string sQueryValues;
            if (lblProdinsert.Text == "noauto")
            {
                ((DataAccess)Session["App"]).PutOrderItem(4, 1); //inserts 1mosupplyshipping product
                ((DataAccess)Session["App"]).PutOrderItem(3, 1); //inserts 1mosupply product

                //insert 1Month supply shipping product
                //sQueryValues = " values (" + Session["listid"] + ", 352, 7, 4,'1MoSupplyShipping', 5.95 ,1)";// +productid + "," + ProdtypeID + ", '" + productdesc + "', " + ProdRev + ", " + productqty + ")";
                //qExecute(sQuery + sQueryValues);

                //sQueryValues = " values (" + Session["listid"] + ", 352, 11, 6,'1MoSupply', 59.95 , 1)";
                //qExecute(sQuery + sQueryValues);
            }
            else if (lblProdinsert.Text == "auto")
            {
                ((DataAccess)Session["App"]).PutOrderItem(2, 1); //inserts regularshipping product
                ((DataAccess)Session["App"]).PutOrderItem(1, 1); //inserts autoship product

                //sQueryValues = " values (" + Session["listid"] + ", 352, 6, 4,'RegularShipping', 7.95 , 1)";
                //qExecute(sQuery + sQueryValues);

                //sQueryValues = " values (" + Session["listid"] + ", 352, 10, 6,'Autoship', 0.00, 1)";
                //qExecute(sQuery + sQueryValues);
                ////lblProdinsert.Text = "autoship";
            }
            if (cbRushShipping.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(7, 1); //inserts rush shipping product

                //sQueryValues = " values (" + Session["listid"] + ", 352, 9, 5,'RushShipping', 7.00 , 1)";
                //qExecute(sQuery + sQueryValues);
            }
            if (cbStressReliefStrips.Checked)
            {
                ((DataAccess)Session["App"]).PutOrderItem(6, 1); //inserts stressreliefstrips product
                //sQueryValues = " values (" + Session["listid"] + ", 352, 8, 5,'StressReliefStrips', 29.95 , 1)";
                //qExecute(sQuery + sQueryValues);
            }
            //These two lines should be fairly standard - they write the in-memory tables to the Database
            ((DataAccess)Session["App"]).CommitCallData();
            ((DataAccess)Session["App"]).CommitOrder();
            return;
        }
        else
        {
            NonSaleDispo.Visible = true;
        }

    }

    //gets initial rebuttal for autoship
    protected void btnAutoDiscRebuttal_Click(object sender, EventArgs e)
    {
        pnlNoAuto.Visible = false;
        pnlAutoDiscRebuttal.Visible = true;
        pnlFinalRebuttal.Visible = false;
        pnlDispo.Visible = false;
        btnAutoDiscRebuttal.Visible = false;
    }

    //gets second rebuttal for autoship
    protected void rblAutoDiscRebuttal_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (rblAutoDiscRebuttal.SelectedIndex == 0)
        {
            //lblAutoDiscYes.Visible = true;
            //lblAutoDiscYes.Text = "Please select autoship from the products drop down list on the right and hit add.";
            pnlNoAuto.Visible = false;
        }
        else
        {
            pnlAutoDiscRebuttal.Visible = false;
            //lblAutoDiscYes.Visible = false;
            pnlNoAuto.Visible = true;
        }
    }

    //gets first rebuttal to pitch 1-month supply
    protected void rblNoAuto_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (rblNoAuto.SelectedIndex == 0)
        {
            //lblAutoDiscYes.Visible = true;
            //lblAutoDiscYes.Text = "Please select 1-month supply from the products drop down list on the right and hit add.";
            pnlFinalRebuttal.Visible = false;

        }
        else
        {
            pnlNoAuto.Visible = false;
            //lblAutoDiscYes.Visible = false;
            pnlFinalRebuttal.Visible = true;
        }
    }

    //final rebuttal for 1-month supply
    protected void rblFinalRebuttal_SelectedIndexChanged(object sender, EventArgs e)
    {

        //lblAutoDiscYes.Visible = true;

        //makes dispositionddl available if the customer doesn't want to order
        if (rblFinalRebuttal.SelectedIndex == 1)
        {
            pnlFinalRebuttal.Visible = false;
            //lblAutoDiscYes.Text = "Please end call, select a disposition, and hit next";
            pnlDispo.Visible = true;
        }
        else
        {
            //lblAutoDiscYes.Text = "Please select 1-month supply from the products drop down list on the right and hit add.";
        }
    }

    //toggles additional shipping information and fills shipping info with previously given info
    protected void cbShip_CheckedChanged(object sender, EventArgs e)
    {
        //tbshipFirstName.Text = tbFirstName.Text;
        //tbshipLastName.Text = tbLastName.Text;
        //tbshipAddr.Text = tbAddr.Text;
        //tbshipAddr2.Text = tbAddr2.Text;
        //tbshipCity.Text = tbCity.Text;
        //ddlShipState.SelectedIndex = ddlState.SelectedIndex;
        //ddlShipCanadaState.SelectedIndex = ddlCanadaState.SelectedIndex;
        //if (ddlState.Visible) { ddlShipState.Visible = true; ddlShipCanadaState.Visible = false; }
        //else { ddlShipState.Visible = false; ddlShipCanadaState.Visible = true; }
        //tbshipZip.Text = tbZip.Text;
        //ddlShipCountry.SelectedIndex = ddlCountry.SelectedIndex;

        if (cbShip.Checked)
        {
            pnlShip.Visible = true;
        }
        else
        {
            pnlShip.Visible = false;
        }
        return;
    }
    protected void cbManualCity_CheckedChanged(object sender, EventArgs e)
    {
        if (cbManualCity.Checked)
        {
            tbCity.Visible = true;
            ddlCity.Visible = false;
            //validator for ddlcity
            RequiredFieldValidator23.Visible = false;
            //validator for tbcity
            RequiredFieldValidator27.Visible = true;
        }
        else
        {
            tbCity.Visible = false;
            ddlCity.Visible = true;
            RequiredFieldValidator23.Visible = true;
            RequiredFieldValidator27.Visible = false;
        }

    }
    protected void cbManualShipCity_CheckedChanged(object sender, EventArgs e)
    {
        Page.SetFocus(ddlShipCountry);

        if (cbManualShipCity.Checked)
        {
            tbShipCity.Visible = true;
            ddlShipCity.Visible = false;
            RequiredFieldValidator24.Visible = false;
            RequiredFieldValidator28.Visible = true;
        }
        else
        {
            tbShipCity.Visible = false;
            ddlShipCity.Visible = true;
            RequiredFieldValidator24.Visible = true;
            RequiredFieldValidator28.Visible = false;
        }
    }
    protected void ddlPayMethod_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlPayMethod.SelectedItem.Value.ToString() == "CreditCard" || ddlPayMethod.SelectedItem.Value.ToString() == "DebitCard")
        {
            pnlCCInfo.Visible = true;
            pnlBankInfo.Visible = false;
            pnlCCSale.Visible = true;
        }
        else
        {
            pnlBankInfo.Visible = true;
            pnlCCInfo.Visible = false;
            pnlCCSale.Visible = false;
        }
        return;
    }

    protected void cbStressReliefStrips_CheckedChanged(object sender, EventArgs e)
    {
        if (cbStressReliefStrips.Checked)
        {
            Session["total"] = Convert.ToDouble(Session["total"]) + 29.95;
        }
        else { Session["total"] = Convert.ToDouble(Session["total"]) - 29.95; }
        return;
    }

    protected void cbRushShipping_CheckedChanged(object sender, EventArgs e)
    {
        if (cbRushShipping.Checked)
        {
            Session["total"] = Convert.ToDouble(Session["total"]) + 7.00;
        }
        else
        {
            Session["total"] = Convert.ToDouble(Session["total"]) - 7.00;
        }
        return;
    }
    //protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlCountry.SelectedIndex == 0)
    //    {
    //        ddlState.Visible = true;
    //        ddlCanadaState.Visible = false;
    //    }
    //    else
    //    {
    //        ddlState.Visible = false;
    //        ddlCanadaState.Visible = true;
    //    }
    //    return;
    //}
    //protected void ddlShipCountry_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlShipCountry.SelectedIndex == 0)
    //    {
    //        ddlShipState.Visible = true;
    //        ddlShipCanadaState.Visible = false;
    //    }
    //    else
    //    {
    //        ddlShipState.Visible = false;
    //        ddlShipCanadaState.Visible = true;
    //    }
    //}
    //private static bool IsValidNumber(string number)
    //{
    //    int[] DELTAS = new int[] { 0, 1, 2, 3, 4, -4, -3, -2, -1, 0 };
    //    int checksum = 0;
    //    char[] chars = number.ToCharArray();
    //    for (int i = chars.Length - 1; i > -1; i--)
    //    {
    //        int j = ((int)chars[i]) - 48;
    //        checksum += j;
    //        if (((i - chars.Length) % 2) == 0)
    //            checksum += DELTAS[j];
    //    }

    //    return ((checksum % 10) == 0);
    //}
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        DataAccess.CardType selectedcard = new DataAccess.CardType();
        switch (ddlCardType.SelectedItem.Text.Replace(" ", ""))
        {
            case "Visa":
                selectedcard = DataAccess.CardType.Visa;
                break;
            case "MasterCard":
                selectedcard = DataAccess.CardType.MasterCard;
                break;
            case "AmericanExpress":
                selectedcard = DataAccess.CardType.AmericanExpress;
                break;
            case "Discover":
                selectedcard = DataAccess.CardType.Discover;
                break;
        }
        args.IsValid = ((DataAccess)Session["App"]).IsValidCC(selectedcard, args.Value.ToString());
        //args.IsValid = IsValidNumber(args.Value.ToString());
    }


    //public void qExecute(string sQuery)

    //{
    //    string sConnection = "user id=portaluser;data source=" + Session["servername"] + ";initial catalog=" + Session["projectname"] + ";password=sqluser";
    //    //string sConnection = "server=172.25.10.8;uid=portaluser; pwd=sqluser; database= " + Session["projectname"] + ";";// voicenet_firstcall_2;";//+ Session["projectname"] + ";";
    //    SqlConnection connection = new SqlConnection(sConnection);
    //    SqlCommand command = new SqlCommand(sQuery, connection);
    //    command.Connection.Open();
    //    command.ExecuteNonQuery();
    //    command.Connection.Close();
    //}

    protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid = ((DataAccess)Session["App"]).ValidateRoutingNumber(Convert.ToInt32(args.Value));
    }

    protected void CustomValidator3_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (tbExpYear.Text == rvExpYear.MinimumValue.ToString())
        {
            if (Convert.ToInt32(args.Value) < Convert.ToInt32(DateTime.Today.ToString("MM")))
            {
                args.IsValid = false;

            }
        }

    }
    protected void btnSearchZip_Click(object sender, EventArgs e)
    {
        string msg;
        msg = "Please select a city";
        ddlCity.Items.Clear();
        ddlCity.Enabled = true;

        if (System.Text.RegularExpressions.Regex.IsMatch(tbZip.Text.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {

                GeoPlaces g = new GeoPlaces();

                AuthenticationHeader authHeader = new AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                //GeoPlaceDistance[] places = g.GetPlacesWithin("Los Angeles", "CA", 10, GeoPlaceType.ZipCode);
                GeoPlaceDistance[] places = g.GetPlacesInside(tbZip.Text, "");

                for (int i = 0; i < places.Length; i++)
                {
                    GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddlCity.Items.Add(li);
                }

                ddlState.Items.Clear();
                ddlState.Items.Add(ddlCity.SelectedItem.Value.Split(",".ToCharArray())[0]);

                //ddlCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(tbZip.Text.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddlCountry.SelectedValue = "CANADA";
                }
                else
                {
                    ddlCountry.SelectedValue = "USA";
                }

                if (ddlCity.Items.Count == 1)
                {
                    ddlCity.Enabled = false;

                    //tbState.Text += ddlCity.SelectedItem.Value.ToString();
                }
                else if (ddlCity.Items.Count <= 0)
                {
                    msg = "No Cities Found";
                    //    ddlCity.Items.Add("No Cities Found");
                    ddlCity.Enabled = false;
                }
                else
                {
                }
            }
            catch
            {
                msg = "No Cities Found";
                // ddlCity.Items.Add("No Cities Found");
                ddlCity.Enabled = false;
            }
        }
        else
        {
            msg = "Invalid Zip";
            //ddlCity.Items.Add("Invalid Zip");
            ddlCity.Enabled = false;
        }
        ListItem liDefault = new ListItem(msg, "0");
        ddlCity.Items.Insert(0, liDefault);
        ddlCity.SelectedIndex = 0;
    }
    protected void btnSearchZipShip_Click(object sender, EventArgs e)
    {
        Page.SetFocus(ddlShipCountry);
        string msg;
        msg = "Please select a city";
        ddlShipCity.Items.Clear();
        ddlShipCity.Enabled = true;

        if (System.Text.RegularExpressions.Regex.IsMatch(tbShipZip.Text.ToUpper(), @"(^\d{5}$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
        {
            try
            {

                GeoPlaces g = new GeoPlaces();

                AuthenticationHeader authHeader = new AuthenticationHeader();
                authHeader.SessionID = "6JV2ZA4lgG1YRR+HG+JU27QWk9zI3rpRWY2iG2mzNPcdieEQXfQv0OUY0EZ+pOTxhwI1NCuF7b2oY+U/bozy0mhjFHmpaXvb";
                g.AuthenticationHeaderValue = authHeader;

                //GeoPlaceDistance[] places = g.GetPlacesWithin("Los Angeles", "CA", 10, GeoPlaceType.ZipCode);
                GeoPlaceDistance[] places = g.GetPlacesInside(tbShipZip.Text, "");

                for (int i = 0; i < places.Length; i++)
                {
                    GeoPlaceDistance place = places[i];
                    ListItem li = new ListItem(place.ToPlace, place.ToState + "," + place.ToPlace);
                    ddlShipCity.Items.Add(li);
                }

                ddlShipState.Items.Clear();
                ddlShipState.Items.Add(ddlShipCity.SelectedItem.Value.Split(",".ToCharArray())[0]);

                //ddlShipCity.SelectedIndex = 0;

                if (System.Text.RegularExpressions.Regex.IsMatch(tbShipZip.Text.ToUpper(), @"(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)"))
                {
                    ddlShipCountry.SelectedValue = "CANADA";
                }
                else
                {
                    ddlShipCountry.SelectedValue = "USA";
                }

                if (ddlShipCity.Items.Count == 1)
                {
                    ddlShipCity.Enabled = false;

                    //tbState.Text += ddlShipCity.SelectedItem.Value.ToString();
                }
                else if (ddlShipCity.Items.Count <= 0)
                {
                    msg = "No Cities Found";
                    //ddlShipCity.Items.Add("No Cities Found");
                    ddlShipCity.Enabled = false;
                }
                else
                {
                }
            }
            catch
            {
                msg = "No Cities Found";
                //ddlShipCity.Items.Add("No Cities Found");
                ddlShipCity.Enabled = false;
            }
        }
        else
        {
            msg = "Invalid Zip";
            //ddlShipCity.Items.Add("Invalid Zip");
            ddlShipCity.Enabled = false;
        }
        ListItem liDefault = new ListItem(msg, "0");
        ddlShipCity.Items.Insert(0, liDefault);
        ddlShipCity.SelectedIndex = 0;

    }
}